﻿// Copyright 2009 William P. Hickey Jr. and William U. Walker
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//     
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//  
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;

namespace CSReporter
{
    public class StatusText : INotifyPropertyChanged
    {
        private string groupName;
        private string status1;
        private string status1R;
        private string status1Y;
        private string status1G;
        private string status1W;
        private string status2;
        private string status2R;
        private string status2Y;
        private string status2G;
        private string status2W;
        private string status3;
        private string status3R;
        private string status3Y;
        private string status3G;
        private string status3W;
        private string status4;
        private string status4R;
        private string status4Y;
        private string status4G;
        private string status4W;
        private string status5;
        private string status5R;
        private string status5Y;
        private string status5G;
        private string status5W;
        private string status6;
        private string status6R;
        private string status6Y;
        private string status6G;
        private string status6W;
        private string status7;
        private string status7R;
        private string status7Y;
        private string status7G;
        private string status7W;
        private string status8;
        private string status8R;
        private string status8Y;
        private string status8G;
        private string status8W;
        private string status9;
        private string status9R;
        private string status9Y;
        private string status9G;
        private string status9W;
        private string status10;
        private string status10R;
        private string status10Y;
        private string status10G;
        private string status10W;
        private string status11;
        private string status11R;
        private string status11Y;
        private string status11G;
        private string status11W;
        private string status12;
        private string status12R;
        private string status12Y;
        private string status12G;
        private string status12W;
        private string status13;
        private string status13R;
        private string status13Y;
        private string status13G;
        private string status13W;
        private string status14;
        private string status14R;
        private string status14Y;
        private string status14G;
        private string status14W;
        private string status15;
        private string status15R;
        private string status15Y;
        private string status15G;
        private string status15W;
        private string status16;
        private string status16R;
        private string status16Y;
        private string status16G;
        private string status16W;

        public string GroupName
        {
            get { return groupName; }
            set
            {
                groupName = value == null ? null:value.Substring(0, Math.Min(value.Length, 25)).Trim();
                this.NotifyPropertyChanged("GroupName");
            }
        }

        public string Status1
        {
            get { return status1; }
            set {
                status1 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status1");
            }
        }

        public string Status1R
        {
            get { return status1R; }
            set
            {
                status1R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status1R");
            }
        }

        public string Status1Y
        {
            get { return status1Y; }
            set
            {
                status1Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status1Y");
            }
        }

        public string Status1G
        {
            get { return status1G; }
            set
            {
                status1G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status1G");
            }
        }

        public string Status1W
        {
            get { return status1W; }
            set
            {
                status1W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status1W");
            }
        }

        public string Status2
        {
            get { return status2; }
            set
            {
                status2 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status2");
            }
        }

        public string Status2R
        {
            get { return status2R; }
            set
            {
                status2R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status2R");
            }
        }

        public string Status2Y
        {
            get { return status2Y; }
            set
            {
                status2Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status2Y");
            }
        }

        public string Status2G
        {
            get { return status2G; }
            set
            {
                status2G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status2G");
            }
        }

        public string Status2W
        {
            get { return status2W; }
            set
            {
                status2W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status2W");
            }
        }

        public string Status3
        {
            get { return status3; }
            set
            {
                status3 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status3");
            }
        }

        public string Status3R
        {
            get { return status3R; }
            set
            {
                status3R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status3R");
            }
        }

        public string Status3Y
        {
            get { return status3Y; }
            set
            {
                status3Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status3Y");
            }
        }

        public string Status3G
        {
            get { return status3G; }
            set
            {
                status3G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status3G");
            }
        }

        public string Status3W
        {
            get { return status3W; }
            set
            {
                status3W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status3W");
            }
        }

        public string Status4
        {
            get { return status4; }
            set
            {
                status4 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status4");
            }
        }

        public string Status4R
        {
            get { return status4R; }
            set
            {
                status4R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status4R");
            }
        }

        public string Status4Y
        {
            get { return status4Y; }
            set
            {
                status4Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status4Y");
            }
        }

        public string Status4G
        {
            get { return status4G; }
            set
            {
                status4G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status4G");
            }
        }

        public string Status4W
        {
            get { return status4W; }
            set
            {
                status4W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status4W");
            }
        }

        public string Status5
        {
            get { return status5; }
            set
            {
                status5 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status5");
            }
        }

        public string Status5R
        {
            get { return status5R; }
            set
            {
                status5R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status5R");
            }
        }

        public string Status5Y
        {
            get { return status5Y; }
            set
            {
                status5Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status5Y");
            }
        }

        public string Status5G
        {
            get { return status5G; }
            set
            {
                status5G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status5G");
            }
        }

        public string Status5W
        {
            get { return status5W; }
            set
            {
                status5W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status5W");
            }
        }

        public string Status6
        {
            get { return status6; }
            set
            {
                status6 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status6");
            }
        }

        public string Status6R
        {
            get { return status6R; }
            set
            {
                status6R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status6R");
            }
        }

        public string Status6Y
        {
            get { return status6Y; }
            set
            {
                status6Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status6Y");
            }
        }

        public string Status6G
        {
            get { return status6G; }
            set
            {
                status6G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status6G");
            }
        }

        public string Status6W
        {
            get { return status6W; }
            set
            {
                status6W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status6W");
            }
        }

        public string Status7
        {
            get { return status7; }
            set
            {
                status7 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status7");
            }
        }

        public string Status7R
        {
            get { return status7R; }
            set
            {
                status7R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status7R");
            }
        }

        public string Status7Y
        {
            get { return status7Y; }
            set
            {
                status7Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status7Y");
            }
        }

        public string Status7G
        {
            get { return status7G; }
            set
            {
                status7G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status7G");
            }
        }

        public string Status7W
        {
            get { return status7W; }
            set
            {
                status7W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status7W");
            }
        }

        public string Status8
        {
            get { return status8; }
            set
            {
                status8 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status8");
            }
        }

        public string Status8R
        {
            get { return status8R; }
            set
            {
                status8R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status8R");
            }
        }

        public string Status8Y
        {
            get { return status8Y; }
            set
            {
                status8Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status8Y");
            }
        }

        public string Status8G
        {
            get { return status8G; }
            set
            {
                status8G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status8G");
            }
        }

        public string Status8W
        {
            get { return status8W; }
            set
            {
                status8W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status8W");
            }
        }

        public string Status9
        {
            get { return status9; }
            set
            {
                status9 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status9");
            }
        }

        public string Status9R
        {
            get { return status9R; }
            set
            {
                status9R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status9R");
            }
        }

        public string Status9Y
        {
            get { return status9Y; }
            set
            {
                status9Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status9Y");
            }
        }

        public string Status9G
        {
            get { return status9G; }
            set
            {
                status9G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status9G");
            }
        }

        public string Status9W
        {
            get { return status9W; }
            set
            {
                status9W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status9W");
            }
        }

        public string Status10
        {
            get { return status10; }
            set
            {
                status10 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status10");
            }
        }

        public string Status10R
        {
            get { return status10R; }
            set
            {
                status10R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status10R");
            }
        }

        public string Status10Y
        {
            get { return status10Y; }
            set
            {
                status10Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status10Y");
            }
        }

        public string Status10G
        {
            get { return status10G; }
            set
            {
                status10G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status10G");
            }
        }

        public string Status10W
        {
            get { return status10W; }
            set
            {
                status10W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status10W");
            }
        }

        public string Status11
        {
            get { return status11; }
            set
            {
                status11 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status11");
            }
        }

        public string Status11R
        {
            get { return status11R; }
            set
            {
                status11R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status11R");
            }
        }

        public string Status11Y
        {
            get { return status11Y; }
            set
            {
                status11Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status11Y");
            }
        }

        public string Status11G
        {
            get { return status11G; }
            set
            {
                status11G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status11G");
            }
        }

        public string Status11W
        {
            get { return status11W; }
            set
            {
                status11W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status11W");
            }
        }

        public string Status12
        {
            get { return status12; }
            set
            {
                status12 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status12");
            }
        }

        public string Status12R
        {
            get { return status12R; }
            set
            {
                status12R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status12R");
            }
        }

        public string Status12Y
        {
            get { return status12Y; }
            set
            {
                status12Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status12Y");
            }
        }

        public string Status12G
        {
            get { return status12G; }
            set
            {
                status12G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status12G");
            }
        }

        public string Status12W
        {
            get { return status12W; }
            set
            {
                status12W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status12W");
            }
        }

        public string Status13
        {
            get { return status13; }
            set
            {
                status13 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status13");
            }
        }

        public string Status13R
        {
            get { return status13R; }
            set
            {
                status13R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status13R");
            }
        }

        public string Status13Y
        {
            get { return status13Y; }
            set
            {
                status13Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status13Y");
            }
        }

        public string Status13G
        {
            get { return status13G; }
            set
            {
                status13G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status13G");
            }
        }

        public string Status13W
        {
            get { return status13W; }
            set
            {
                status13W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status13W");
            }
        }

        public string Status14
        {
            get { return status14; }
            set
            {
                status14 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status14");
            }
        }

        public string Status14R
        {
            get { return status14R; }
            set
            {
                status14R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status14R");
            }
        }

        public string Status14Y
        {
            get { return status14Y; }
            set
            {
                status14Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status14Y");
            }
        }

        public string Status14G
        {
            get { return status14G; }
            set
            {
                status14G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status14G");
            }
        }

        public string Status14W
        {
            get { return status14W; }
            set
            {
                status14W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status14W");
            }
        }

        public string Status15
        {
            get { return status15; }
            set
            {
                status15 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status15");
            }
        }

        public string Status15R
        {
            get { return status15R; }
            set
            {
                status15R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status15R");
            }
        }

        public string Status15Y
        {
            get { return status15Y; }
            set
            {
                status15Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status15Y");
            }
        }

        public string Status15G
        {
            get { return status15G; }
            set
            {
                status15G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status15G");
            }
        }

        public string Status15W
        {
            get { return status15W; }
            set
            {
                status15W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status15W");
            }
        }

        public string Status16
        {
            get { return status16; }
            set
            {
                status16 = value == null ? null:value.Substring(0, Math.Min(value.Length, 100)).Trim();
                this.NotifyPropertyChanged("Status16");
            }
        }

        public string Status16R
        {
            get { return status16R; }
            set
            {
                status16R = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status16R");
            }
        }

        public string Status16Y
        {
            get { return status16Y; }
            set
            {
                status16Y = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status16Y");
            }
        }

        public string Status16G
        {
            get { return status16G; }
            set
            {
                status16G = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status16G");
            }
        }

        public string Status16W
        {
            get { return status16W; }
            set
            {
                status16W = value == null ? null:value.Substring(0, Math.Min(value.Length, 15)).Trim();
                this.NotifyPropertyChanged("Status16W");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public StatusText()
        {
            groupName = "Default";
            status1 = "Status1";
            status1R = "Danger";
            status1Y = "Warning";
            status1G = "Normal";
            status1W = "Unknown";
            status2 = "Status2";
            status2R = "Danger";
            status2Y = "Warning";
            status2G = "Normal";
            status2W = "Unknown";
            status3 = "Status3";
            status3R = "Danger";
            status3Y = "Warning";
            status3G = "Normal";
            status3W = "Unknown";
            status4 = "Status4";
            status4R = "Danger";
            status4Y = "Warning";
            status4G = "Normal";
            status4W = "Unknown";
            status5 = "Status5";
            status5R = "Danger";
            status5Y = "Warning";
            status5G = "Normal";
            status5W = "Unknown";
            status6 = "Status6";
            status6R = "Danger";
            status6Y = "Warning";
            status6G = "Normal";
            status6W = "Unknown";
            status7 = "Status7";
            status7R = "Danger";
            status7Y = "Warning";
            status7G = "Normal";
            status7W = "Unknown";
            status8 = "Status8";
            status8R = "Danger";
            status8Y = "Warning";
            status8G = "Normal";
            status8W = "Unknown";
            status9 = "Status9";
            status9R = "Danger";
            status9Y = "Warning";
            status9G = "Normal";
            status9W = "Unknown";
            status10 = "Status10";
            status10R = "Danger";
            status10Y = "Warning";
            status10G = "Normal";
            status10W = "Unknown";
            status11 = "Status11";
            status11R = "Danger";
            status11Y = "Warning";
            status11G = "Normal";
            status11W = "Unknown";
            status12 = "Status12";
            status12R = "Danger";
            status12Y = "Warning";
            status12G = "Normal";
            status12W = "Unknown";
            status13 = "Status13";
            status13R = "Danger";
            status13Y = "Warning";
            status13G = "Normal";
            status13W = "Unknown";
            status14 = "Status14";
            status14R = "Danger";
            status14Y = "Warning";
            status14G = "Normal";
            status14W = "Unknown";
            status15 = "Status15";
            status15R = "Danger";
            status15Y = "Warning";
            status15G = "Normal";
            status15W = "Unknown";
            status16 = "Status16";
            status16R = "Danger";
            status16Y = "Warning";
            status16G = "Normal";
            status16W = "Unknown";
        }

        private void NotifyPropertyChanged(string name)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
    }

    public class StatusTextList : BindingList<StatusText>
    {
        // Static initialization ensures thread safety.
        private static readonly StatusTextList singletonInstance = new StatusTextList();

        private StatusTextList() { }

        public static StatusTextList GetStatusTextList()
        {
            if (singletonInstance.Items.Count == 0)
                singletonInstance.Add(new StatusText());
            return singletonInstance;
        }

        public void ReadXml(string fileName)
        {
            if (File.Exists(fileName))
            {
                Clear();
                XmlSerializer deserializer = new XmlSerializer(typeof(List<StatusText>));
                using (TextReader textReader = new StreamReader(fileName))
                    foreach (StatusText st in (List<StatusText>)deserializer.Deserialize(textReader))
                        Add(st);
            }
        }

        public void WriteXml(string fileName)
        {
            if (Directory.GetParent(fileName).Exists)
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List<StatusText>));
                using (TextWriter textWriter = new StreamWriter(fileName))
                    serializer.Serialize(textWriter, Items);
            }
        }
    }
}
